//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "canlib\\canlib.h"
#include "process.h"
#include <mmsystem.h>
#include "Unit1.h"
#include "Unit2.h"

#include "config.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TMainForm *MainForm;
#define DIAG_Req_ID   0x740

#define DEFAULT_SESSION       0x01
#define PROGRAMMING_SESSION   0x02
#define ENDOFLINE_SESSION     0x03
#define SEC_REQ_SEED_03       0x04
#define SEC_SEND_KEY_04       0x05
#define SEC_REQ_SEED_05       0x06
#define SEC_SEND_KEY_06       0x07

bool ReceiveSts;
int stat;
long id;
AnsiString Tempx="";
unsigned int dlc, flags;
Word POLYNOM_1;
UINT g_TIMEID;
unsigned char RxData[8];

unsigned char counterCycle1=9;
unsigned char counterCycle2=9;
unsigned char counterCycle3=9;
DWORD Handle1,Handle2;
//unsigned int long OldTimeStamp=0, LatestTimeStamp=0;

unsigned long timestamp=0;
unsigned long timestamp_ID_391=0;
unsigned long timestamp_ID_398=0;
unsigned long timestamp_ID_600=0;
unsigned long timestamp_ID_3C0=0;
unsigned long timestamp_ID_52B=0;
unsigned long timestamp_ID_7C0=0;
unsigned int time_Period=0;

unsigned char send_index_U8 = 0;
Word calKey = 0;

unsigned char DiagnosticSession[8]={0x02,0x10,0x01,0x00,0x00,0x00,0x00,0x00};
unsigned char TxFlowControl[8]=    {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

unsigned char RDDataByLID[8]=      {0x03,0x22,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned char WRDataByLID[8]=      {0x04,0x2E,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned char WRDataByLID1[8]=     {0x21,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned char IOControl[8]=        {0x05,0x2F,0x61,0x00,0x00,0x00,0x00,0x00};

unsigned char SecurityAccess1[8]=  {0x02,0x27,0x03,0x00,0x00,0x00,0x00,0x00};
unsigned char SecurityAccess2[8]=  {0x04,0x27,0x04,0xF4,0x80,0x00,0x00,0x00};

unsigned char RoutineControl[8]=   {0x04,0x31,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned char Reset[8]=            {0x02,0x11,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned char ReadDTC[8]=          {0x03,0x19,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned char ClearDTC[8]=         {0x04,0x14,0xFF,0xFF,0xFF,0x00,0x00,0x00};

unsigned char CommunicationCtrl[8]={0x03,0x28,0x00,0x01,0x00,0x00,0x00,0x00};
unsigned char TesterPresent[8]=    {0x02,0x3E,0x00,0x00,0x00,0x00,0x00,0x00};

unsigned char Errorcode[8]=        {0x03,0x7F,0x00,0x00,0x00,0x00,0x00,0x00};

unsigned char Msg740[8];
unsigned char Msg750[8];
void Cycle10ms(void);
void Cycle100ms(void);
void Cycle1000ms(void);
void StartDiagnosticComm(void);


void WINAPI TaskCycle(UINT uID,UINT MSG,DWORD DWUSER,DWORD DW1,DWORD DW2)
{
    Cycle10ms();
}
//---------------------------------------------------------------------------

void TMainForm::Start_Timer(unsigned int ms_time_val)
{
    TIMECAPS TC;
    UINT TIMERES=0;
    UINT TIMEID;
    unsigned int Interval;

    Interval=(int)ms_time_val;

    if(timeGetDevCaps(&TC,sizeof(TIMECAPS))!=TIMERR_NOERROR)
    {
         exit(0);
    }
    timeBeginPeriod(TIMERES);

    TIMEID = timeSetEvent(Interval,TIMERES,&(LPTIMECALLBACK)TaskCycle,0,TIME_PERIODIC);
    g_TIMEID=TIMEID;
}
//---------------------------------------------------------------------------
void TMainForm::End_timer(void)
{
    timeKillEvent(g_TIMEID);
    timeEndPeriod(0);
}
//---------------------------------------------------------------------------
void Cycle10ms(void)
{
    switch(counterCycle1--)
    {
    case 9:
         break;
    case 8:
         break;
    case 7:
         break;
    case 6:
         StartDiagnosticComm();
         break;
    case 5:
         break;
    case 4:
         break;
    case 3:
         break;
    case 2:
         break;
    case 1:
         break;
    case 0:
         //Cycle100ms();
         counterCycle1=9;
         break;
    default:
         break;
    }
}
//---------------------------------------------------------------------------
void StartDiagnosticComm(void)
{
     unsigned char temp_send_index_U8;

     temp_send_index_U8 = send_index_U8;
     send_index_U8 = 0;
     memset(Msg740,0,8);

     switch(temp_send_index_U8)
     {
     case DEFAULT_SESSION:
          Msg740[0] = 0x02;
          Msg740[1] = 0x10;
          Msg740[2] = 0x01;

          if(canWrite(Handle1,0x740,Msg740,8,0)==canOK)
          {
              MainForm->MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(Msg740[0],2) + "  "
                                  + IntToHex(Msg740[1],2) + "  "
                                  + IntToHex(Msg740[2],2) + "  "
                                  + IntToHex(Msg740[3],2) + "  "
                                  + IntToHex(Msg740[4],2) + "  "
                                  + IntToHex(Msg740[5],2) + "  "
                                  + IntToHex(Msg740[6],2) + "  "
                                  + IntToHex(Msg740[7],2) + "  "
                                 );
          }
          break;

     case PROGRAMMING_SESSION:
          Msg740[0] = 0x02;
          Msg740[1] = 0x10;
          Msg740[2] = 0x02;

          if(canWrite(Handle1,0x740,Msg740,8,0)==canOK)
          {
              MainForm->MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(Msg740[0],2) + "  "
                                  + IntToHex(Msg740[1],2) + "  "
                                  + IntToHex(Msg740[2],2) + "  "
                                  + IntToHex(Msg740[3],2) + "  "
                                  + IntToHex(Msg740[4],2) + "  "
                                  + IntToHex(Msg740[5],2) + "  "
                                  + IntToHex(Msg740[6],2) + "  "
                                  + IntToHex(Msg740[7],2) + "  "
                                 );
          }
          break;
     case ENDOFLINE_SESSION:
          Msg740[0] = 0x02;
          Msg740[1] = 0x10;
          Msg740[2] = 0x03;

          if(canWrite(Handle1,0x740,Msg740,8,0)==canOK)
          {
              MainForm->MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(Msg740[0],2) + "  "
                                  + IntToHex(Msg740[1],2) + "  "
                                  + IntToHex(Msg740[2],2) + "  "
                                  + IntToHex(Msg740[3],2) + "  "
                                  + IntToHex(Msg740[4],2) + "  "
                                  + IntToHex(Msg740[5],2) + "  "
                                  + IntToHex(Msg740[6],2) + "  "
                                  + IntToHex(Msg740[7],2) + "  "
                                 );
          }
          break;

     case SEC_REQ_SEED_03:
          Msg740[0] = 0x02;
          Msg740[1] = 0x27;
          Msg740[2] = 0x03;

          if(canWrite(Handle1,0x740,Msg740,8,0)==canOK)
          {
              MainForm->MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(Msg740[0],2) + "  "
                                  + IntToHex(Msg740[1],2) + "  "
                                  + IntToHex(Msg740[2],2) + "  "
                                  + IntToHex(Msg740[3],2) + "  "
                                  + IntToHex(Msg740[4],2) + "  "
                                  + IntToHex(Msg740[5],2) + "  "
                                  + IntToHex(Msg740[6],2) + "  "
                                  + IntToHex(Msg740[7],2) + "  "
                                 );
          }
          break;
     case SEC_SEND_KEY_04:
          Msg740[0] = 0x04;
          Msg740[1] = 0x27;
          Msg740[2] = 0x04;
          Msg740[3] = calKey>>8;
          Msg740[4] = calKey&0xFF;

          if(canWrite(Handle1,0x740,Msg740,8,0)==canOK)
          {
              MainForm->MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(Msg740[0],2) + "  "
                                  + IntToHex(Msg740[1],2) + "  "
                                  + IntToHex(Msg740[2],2) + "  "
                                  + IntToHex(Msg740[3],2) + "  "
                                  + IntToHex(Msg740[4],2) + "  "
                                  + IntToHex(Msg740[5],2) + "  "
                                  + IntToHex(Msg740[6],2) + "  "
                                  + IntToHex(Msg740[7],2) + "  "
                                 );
          }
          break;
     default:
          break;
     }


}


//---------------------------------------------------------------------------
/* Function Name:Word calcKey(Word seed)
* Description: Calculate key to a given seed.
* Param: seed - Seed to which the key has to be calculated
* Return:Word - Calculated key*/
static Word calcKey(Word seed)
{
#define TOPBIT 0x8000
#define POLYNOM_1 0x8408
#define POLYNOM_2 0x8025
#define BITMASK 0x0080
#define INITIAL_REMINDER 0xFFFE
#define MSG_LEN 2 /* seed length in bytes */
Byte bSeed[2];
Word remainder;
Byte n;
Byte i;
bSeed[0] = (Byte)(seed >> 8); /* MSB */
bSeed[1] = (Byte)seed; /* LSB */
remainder = INITIAL_REMINDER;

    for (n = 0; n < MSG_LEN; n++)
    {
    /* Bring the next byte into the remainder. */
    remainder ^= ((bSeed[n]) << 8);
    /* Perform modulo-2 division, a bit at a time. */
        for (i = 0; i < 8; i++)
        {
        /* Try to divide the current data bit. */
          if (remainder & TOPBIT)
          {
            if(remainder & BITMASK)
            {
              remainder = (remainder << 1) ^ POLYNOM_1;
            }
            else
            {
              remainder = (remainder << 1) ^ POLYNOM_2;
            }
         }
         else
         {
           remainder = (remainder << 1);
         }
       }
    }
/* The final remainder is the key */
return remainder;
}

//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::Button5Click(TObject *Sender)
{
    MemoText->Clear();
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::Button4Click(TObject *Sender)
{
    AnsiString S_FileName;
    SaveDialog->DefaultExt="txt";
    SaveDialog->FileName="*.txt";
    if(SaveDialog->Execute())
    {
      S_FileName=SaveDialog->FileName;
      MemoText->Lines->SaveToFile(S_FileName);
    }
}
//---------------------------------------------------------------------------


void __fastcall TMainForm::Button13Click(TObject *Sender)
{
    //ConfigForm->ShowModal();
}
//---------------------------------------------------------------------------


void __fastcall TMainForm::FormCreate(TObject *Sender)
{
    int i,chanCount;
    char name[64];
    //-------------------------
    canInitializeLibrary();
    if(canGetNumberOfChannels(&chanCount)<0)return;

    StatusBar1->Panels->Items[0]->Text="Please connect Kvaser to computer!";
    for(i=0;i<chanCount;i++)
    {
        canGetChannelData(i, canCHANNELDATA_CHANNEL_NAME, name,sizeof(name));
        StatusBar1->Panels->Items[0]->Text="CAN communication successful!";
        StatusBar1->Panels->Items[1]->Text="500000bit/s";
    }
    //--------------------------
    //canGetBusParams??

}
//---------------------------------------------------------------------------


void __fastcall TMainForm::Button_StartCommClick(TObject *Sender)
{
     Handle1 = canOpenChannel(0, canWANT_VIRTUAL);
     if (Handle1 < 0)
     {
          ShowMessage("Can't open channel.");
     }

    canBusOff(Handle1);

    canSetNotify(Handle1,Handle,canNOTIFY_RX);
    canBusOn(Handle1);

    BusStateTimer->Enabled=true;
    Start_Timer(1);
    switch(CBDiagMode->ItemIndex)
    {
    case 0:
         send_index_U8 =  DEFAULT_SESSION;
         break;
    case 1:
         send_index_U8 =  PROGRAMMING_SESSION;
         break;
    case 2:
         send_index_U8 =  ENDOFLINE_SESSION;
         break;
    default:
         send_index_U8 =  DEFAULT_SESSION;
         break;
    }

}
//---------------------------------------------------------------------------

void __fastcall TMainForm::Button_StopCOMMClick(TObject *Sender)
{
    //CANRxTimer->Enabled=false;
    BusStateTimer->Enabled=false;
    canBusOff(Handle1);
    End_timer();

}

void __fastcall TMainForm::WMCanLib(TWMCanLib& Message)
{
    //int stat;
   //long id;
    //unsigned int dlc, flags;
    unsigned char RxData[8];
    do {
          stat=canRead(Handle1, &id, RxData, &dlc, &flags, &timestamp);
          if ((stat == canOK ) &&  (dlc>0))
          {
               switch(id)
               {
               case 0x750:
                    if(RxData[1] != 0x7E )
                    {
                       MemoText->Lines->Add(IntToHex(0x750,3) +  "        "
                                             + IntToHex(RxData[0],2) + "  "
                                             + IntToHex(RxData[1],2) + "  "
                                             + IntToHex(RxData[2],2) + "  "
                                             + IntToHex(RxData[3],2) + "  "
                                             + IntToHex(RxData[4],2) + "  "
                                             + IntToHex(RxData[5],2) + "  "
                                             + IntToHex(RxData[6],2) + "  "
                                             + IntToHex(RxData[7],2) );
                    }
                    memcpy(Msg750,RxData,8);
                    CheckResp();
                    break;

               case 0x391:
                    Edit_BCM1_391_ID->Text =   IntToHex(RxData[0],2) + "  "
                                             + IntToHex(RxData[1],2) + "  "
                                             + IntToHex(RxData[2],2) + "  "
                                             + IntToHex(RxData[3],2) + "  "
                                             + IntToHex(RxData[4],2) + "  "
                                             + IntToHex(RxData[5],2) + "  "
                                             + IntToHex(RxData[6],2) + "  "
                                             + IntToHex(RxData[7],2);
                    time_Period = timestamp - timestamp_ID_391;
                    Label__Interval_391->Caption =  time_Period;
                    //Label__Interval_391->Caption =  Label__Interval_391->Caption + "ms";
                    Label2->Visible=true;
                    timestamp_ID_391 = timestamp;
                    break;

               case 0x398:
                    Edit_BCM2_398_ID->Text =   IntToHex(RxData[0],2) + "  "
                                             + IntToHex(RxData[1],2) + "  "
                                             + IntToHex(RxData[2],2) + "  "
                                             + IntToHex(RxData[3],2) + "  "
                                             + IntToHex(RxData[4],2) + "  "
                                             + IntToHex(RxData[5],2) + "  "
                                             + IntToHex(RxData[6],2) + "  "
                                             + IntToHex(RxData[7],2);
                    time_Period = timestamp-timestamp_ID_398;
                    Label__Interval_398->Caption =  time_Period;
                    Label4->Visible=true;
                    timestamp_ID_398 = timestamp;
                    break;

               case 0x600:
                    Edit_NWMBCM_600_ID->Text = IntToHex(RxData[0],2) + "  "
                                             + IntToHex(RxData[1],2) + "  "
                                             + IntToHex(RxData[2],2) + "  "
                                             + IntToHex(RxData[3],2) + "  "
                                             + IntToHex(RxData[4],2) + "  "
                                             + IntToHex(RxData[5],2) + "  "
                                             + IntToHex(RxData[6],2) + "  "
                                             + IntToHex(RxData[7],2);
                    time_Period = timestamp-timestamp_ID_600;
                    Label__Interval_600->Caption =  time_Period;
                    Label6->Visible=true;
                    timestamp_ID_600 = timestamp;
                    break;

               case 0x3C0:
                    Edit_BCM4_3C0_ID->Text =   IntToHex(RxData[0],2) + "  "
                                             + IntToHex(RxData[1],2) + "  "
                                             + IntToHex(RxData[2],2) + "  "
                                             + IntToHex(RxData[3],2) + "  "
                                             + IntToHex(RxData[4],2) + "  "
                                             + IntToHex(RxData[5],2) + "  "
                                             + IntToHex(RxData[6],2) + "  "
                                             + IntToHex(RxData[7],2);
                    time_Period = timestamp-timestamp_ID_3C0;
                    Label__Interval_3C0->Caption =  time_Period;
                    Label8->Visible=true;
                    timestamp_ID_3C0 = timestamp;
                    break;

               case 0x52B:
                    Edit_BCM3_52B_ID->Text =   IntToHex(RxData[0],2) + "  "
                                             + IntToHex(RxData[1],2) + "  "
                                             + IntToHex(RxData[2],2) + "  "
                                             + IntToHex(RxData[3],2) + "  "
                                             + IntToHex(RxData[4],2) + "  "
                                             + IntToHex(RxData[5],2) + "  "
                                             + IntToHex(RxData[6],2) + "  "
                                             + IntToHex(RxData[7],2);
                    time_Period = timestamp-timestamp_ID_52B;
                    Label__Interval_52B->Caption =  time_Period;
                    Label10->Visible=true;
                    timestamp_ID_52B = timestamp;
                    break;

               case 0x7C0:
                    Edit_BCMREL_7C0_ID->Text = IntToHex(RxData[0],2) + "  "
                                             + IntToHex(RxData[1],2) + "  "
                                             + IntToHex(RxData[2],2) + "  "
                                             + IntToHex(RxData[3],2) + "  "
                                             + IntToHex(RxData[4],2) + "  "
                                             + IntToHex(RxData[5],2);
                    time_Period = timestamp-timestamp_ID_7C0;
                    Label__Interval_7C0->Caption =  time_Period;
                    Label11->Visible=true;
                    timestamp_ID_7C0 = timestamp;
                    break;

               default:
                    break;
               }

          }
          else
          {
              /* do nothing */

          }






    } while (stat == canOK);


}

void  TMainForm::CheckResp(void)
{


    switch(Msg750[0]&0xF0)
    {
    case 0x10:
         if(canWrite(Handle1,0x740,TxFlowControl,8,0)==canOK)
         {
             MemoText->Lines->Add( IntToHex(0x740,3) +  "        "
                                 + IntToHex(TxFlowControl[0],2) + "  "
                                 + IntToHex(TxFlowControl[1],2) + "  "
                                 + IntToHex(TxFlowControl[2],2) + "  "
                                 + IntToHex(TxFlowControl[3],2) + "  "
                                 + IntToHex(TxFlowControl[4],2) + "  "
                                 + IntToHex(TxFlowControl[5],2) + "  "
                                 + IntToHex(TxFlowControl[6],2) + "  "
                                 + IntToHex(TxFlowControl[7],2) );
         }
         else
         {
             /* do nothing */
         }
         break;
    case 0x30:
    Tempx="0x"+Edit12->Text;
    WRDataByLID1[1]= (unsigned char)Tempx.ToInt();

    Tempx="0x"+Edit7->Text;
    WRDataByLID1[2]= (unsigned char)Tempx.ToInt();

    Tempx="0x"+Edit6->Text;
    WRDataByLID1[3]= (unsigned char)Tempx.ToInt();

    Tempx="0x"+Edit5->Text;
    WRDataByLID1[4]= (unsigned char)Tempx.ToInt();

    Tempx="0x"+Edit4->Text;
    WRDataByLID1[5]= (unsigned char)Tempx.ToInt();
    if(canWrite(Handle1,0x740,WRDataByLID1,8,0)==canOK)
    {
      //MemoText->Lines->Add("                      ");
     // MemoText->Lines->Add("CAN Configuration");
      MemoText->Lines->Add(IntToHex(0x740,3)
                              + "        "
                              + IntToHex(WRDataByLID1[0],2) + "  "
                              + IntToHex(WRDataByLID1[1],2) + "  "
                              + IntToHex(WRDataByLID1[2],2) + "  "
                              + IntToHex(WRDataByLID1[3],2) + "  "
                              + IntToHex(WRDataByLID1[4],2) + "  "
                              + IntToHex(WRDataByLID1[5],2) + "  "
                              + IntToHex(WRDataByLID1[6],2) + "  "
                              + IntToHex(WRDataByLID1[7],2) + "  "
                                        );
    }
         break;
    default:
         break;
    }

    switch(Msg750[1])
    {
    case 0x50:
         switch(Msg750[2])
         {
         case 0x01: //default session

              break;
         case 0x02: //programming session
              Timer_Testpresent->Enabled = true;
              break;
         case 0x03: //end of line session
              send_index_U8 = SEC_REQ_SEED_03;

              Timer_Testpresent->Enabled = true;
              break;
         default:
              break;
         }
         break;
    case 0x67:
         switch(Msg750[2])
         {
         case 0x03: //
              //cac key  calKey = cac
              Word seed;
              //calKey = 0xF480;
              seed = (Msg750[3]<<8) + Msg750[4];
              if(seed)
              {
                 calKey = calcKey(seed);
                 send_index_U8 = SEC_SEND_KEY_04;
              }
              else
              {
                  MemoText->Lines->Add(">>ECU is online!");
              }
              break;
         case 0x04: //

              break;
         case 0x05: //
              send_index_U8 = SEC_SEND_KEY_06;
              break;
         case 0x06: //

              break;
         default:
              break;
         }
         break;
    case 0x62:
         break;
    case 0x6E:
         break;
    case 0x59:
         break;
    case 0x71:
         break;

    default:
         break;
    }

  {
   /* switch(Msg750[2]&0xFF)
    {
    case 0x03:
        if(canWrite(Handle1,0x740,SecurityAccess1,8,0)==canOK)
        {
             MemoText->Lines->Add( IntToHex(0x740,3) +  "        "
                                 + IntToHex(SecurityAccess1[0],2) + "  "
                                 + IntToHex(SecurityAccess1[1],2) + "  "
                                 + IntToHex(SecurityAccess1[2],2) + "  "
                                 + IntToHex(SecurityAccess1[3],2) + "  "
                                 + IntToHex(SecurityAccess1[4],2) + "  "
                                 + IntToHex(SecurityAccess1[5],2) + "  "
                                 + IntToHex(SecurityAccess1[6],2) + "  "
                                 + IntToHex(SecurityAccess1[7],2) );
         }
         else
         {
             //do nothing
         }
         break;

    case 0x04:
        if(canWrite(Handle1,0x740,SecurityAccess1,8,0)==canOK)
        {
             MemoText->Lines->Add( IntToHex(0x740,3) +  "        "
                                 + IntToHex(SecurityAccess2[0],2) + "  "
                                 + IntToHex(SecurityAccess2[1],2) + "  "
                                 + IntToHex(SecurityAccess2[2],2) + "  "
                                 + IntToHex(SecurityAccess2[3],2) + "  "
                                 + IntToHex(SecurityAccess2[4],2) + "  "
                                 + IntToHex(SecurityAccess2[5],2) + "  "
                                 + IntToHex(SecurityAccess2[6],2) + "  "
                                 + IntToHex(SecurityAccess2[7],2) );
         }
         else
         {
             // do nothing
         }
         break;

    default:
        break;
    } */
  }
}
//---------------------------------------------------------------------------
void TMainForm::CheckMode(void)
{
    switch(MainForm->CBDiagMode->ItemIndex)
    {
      case 0: //DefaultSession
          DiagnosticSession[2]=0x01;
          if(canWrite(Handle1,0x740,DiagnosticSession,8,0)==canOK)
          {
              MemoText->Lines->Add( IntToHex(0x740,3) +  "        "
                                  + IntToHex(DiagnosticSession[0],2) + "  "
                                  + IntToHex(DiagnosticSession[1],2) + "  "
                                  + IntToHex(DiagnosticSession[2],2) + "  "
                                  + IntToHex(DiagnosticSession[3],2) + "  "
                                  + IntToHex(DiagnosticSession[4],2) + "  "
                                  + IntToHex(DiagnosticSession[5],2) + "  "
                                  + IntToHex(DiagnosticSession[6],2) + "  "
                                  + IntToHex(DiagnosticSession[7],2) );

          }
          else
          {
              /* do nothing */
          }
          break;

      case 1: //ProgrammingSession
          DiagnosticSession[2]=0x02;
          if(canWrite(Handle1,0x740,DiagnosticSession,8,0)==canOK)
          {
              MemoText->Lines->Add( IntToHex(0x740,3) +  "        "
                                  + IntToHex(DiagnosticSession[0],2) + "  "
                                  + IntToHex(DiagnosticSession[1],2) + "  "
                                  + IntToHex(DiagnosticSession[2],2) + "  "
                                  + IntToHex(DiagnosticSession[3],2) + "  "
                                  + IntToHex(DiagnosticSession[4],2) + "  "
                                  + IntToHex(DiagnosticSession[5],2) + "  "
                                  + IntToHex(DiagnosticSession[6],2) + "  "
                                  + IntToHex(DiagnosticSession[7],2) );
          }
          else
          {
              /* do nothing */
          }
          break;

      case 2: //ExtendedDiagnosticSession
          DiagnosticSession[2]=0x03;
          if(canWrite(Handle1,0x740,DiagnosticSession,8,0)==canOK)
          {
              MemoText->Lines->Add( IntToHex(0x740,3) +  "        "
                                  + IntToHex(DiagnosticSession[0],2) + "  "
                                  + IntToHex(DiagnosticSession[1],2) + "  "
                                  + IntToHex(DiagnosticSession[2],2) + "  "
                                  + IntToHex(DiagnosticSession[3],2) + "  "
                                  + IntToHex(DiagnosticSession[4],2) + "  "
                                  + IntToHex(DiagnosticSession[5],2) + "  "
                                  + IntToHex(DiagnosticSession[6],2) + "  "
                                  + IntToHex(DiagnosticSession[7],2) );
          }
          else
          {
              /* do nothing */
          }
          break;

      default:
          break;
    }
}



//---------------------------------------------------------------------------



void __fastcall TMainForm::ReadExcuteClick(TObject *Sender)
{
    switch(CBRead->ItemIndex)
    {
       case 0: // Number Of RF Key
          RDDataByLID[2]=0x60;
          RDDataByLID[3]=0x00;
          if(canWrite(Handle1,0x740,RDDataByLID,8,0)==canOK)
          {
            MemoText->Lines->Add("                      ");
            MemoText->Lines->Add("Read Number Of RF Key");
            MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(RDDataByLID[0],2) + "  "
                                  + IntToHex(RDDataByLID[1],2) + "  "
                                  + IntToHex(RDDataByLID[2],2) + "  "
                                  + IntToHex(RDDataByLID[3],2) + "  "
                                  + IntToHex(RDDataByLID[4],2) + "  "
                                  + IntToHex(RDDataByLID[5],2) + "  "
                                  + IntToHex(RDDataByLID[6],2) + "  "
                                  + IntToHex(RDDataByLID[7],2) + "  "
                                 );
          }

          break;
       case 1: //Vehicle Running Mode
           RDDataByLID[2]=0x60;
           RDDataByLID[3]=0x01;
           if(canWrite(Handle1,0x740,RDDataByLID,8,0)==canOK)
           {
             MemoText->Lines->Add("                      ");
             MemoText->Lines->Add("Read Vehicle Running Mode");
             MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(RDDataByLID[0],2) + "  "
                                  + IntToHex(RDDataByLID[1],2) + "  "
                                  + IntToHex(RDDataByLID[2],2) + "  "
                                  + IntToHex(RDDataByLID[3],2) + "  "
                                  + IntToHex(RDDataByLID[4],2) + "  "
                                  + IntToHex(RDDataByLID[5],2) + "  "
                                  + IntToHex(RDDataByLID[6],2) + "  "
                                  + IntToHex(RDDataByLID[7],2) + "  "
                                 );
           }
           break;
       case 2: //Input Status(Light)
           RDDataByLID[2]=0x60;
           RDDataByLID[3]=0x02;
           if(canWrite(Handle1,0x740,RDDataByLID,8,0)==canOK)
           {
             MemoText->Lines->Add("                      ");
             MemoText->Lines->Add("Read Light Input Status");
             MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(RDDataByLID[0],2) + "  "
                                  + IntToHex(RDDataByLID[1],2) + "  "
                                  + IntToHex(RDDataByLID[2],2) + "  "
                                  + IntToHex(RDDataByLID[3],2) + "  "
                                  + IntToHex(RDDataByLID[4],2) + "  "
                                  + IntToHex(RDDataByLID[5],2) + "  "
                                  + IntToHex(RDDataByLID[6],2) + "  "
                                  + IntToHex(RDDataByLID[7],2) + "  "
                                 );
           }
           break;
       case 3: //Input Status(Window)
           RDDataByLID[2]=0x60;
           RDDataByLID[3]=0x04;
           if(canWrite(Handle1,0x740,RDDataByLID,8,0)==canOK)
           {
             MemoText->Lines->Add("                      ");
             MemoText->Lines->Add("Read Window Input Status");
             MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(RDDataByLID[0],2) + "  "
                                  + IntToHex(RDDataByLID[1],2) + "  "
                                  + IntToHex(RDDataByLID[2],2) + "  "
                                  + IntToHex(RDDataByLID[3],2) + "  "
                                  + IntToHex(RDDataByLID[4],2) + "  "
                                  + IntToHex(RDDataByLID[5],2) + "  "
                                  + IntToHex(RDDataByLID[6],2) + "  "
                                  + IntToHex(RDDataByLID[7],2) + "  "
                                 );
           }
           break;
       case 4: //Input Status(Lock)
           RDDataByLID[2]=0x60;
           RDDataByLID[3]=0x05;
           if(canWrite(Handle1,0x740,RDDataByLID,8,0)==canOK)
           {
             MemoText->Lines->Add("                      ");
             MemoText->Lines->Add("Read Lock Input Status");
             MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(RDDataByLID[0],2) + "  "
                                  + IntToHex(RDDataByLID[1],2) + "  "
                                  + IntToHex(RDDataByLID[2],2) + "  "
                                  + IntToHex(RDDataByLID[3],2) + "  "
                                  + IntToHex(RDDataByLID[4],2) + "  "
                                  + IntToHex(RDDataByLID[5],2) + "  "
                                  + IntToHex(RDDataByLID[6],2) + "  "
                                  + IntToHex(RDDataByLID[7],2) + "  "
                                 );
           }
           break;
       case 5: //Input Status(Door&Hood&Trunk)
           RDDataByLID[2]=0x60;
           RDDataByLID[3]=0x06;
           if(canWrite(Handle1,0x740,RDDataByLID,8,0)==canOK)
           {
             MemoText->Lines->Add("                      ");
             MemoText->Lines->Add("Read Door&Hood&Trunk Input Status");
             MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(RDDataByLID[0],2) + "  "
                                  + IntToHex(RDDataByLID[1],2) + "  "
                                  + IntToHex(RDDataByLID[2],2) + "  "
                                  + IntToHex(RDDataByLID[3],2) + "  "
                                  + IntToHex(RDDataByLID[4],2) + "  "
                                  + IntToHex(RDDataByLID[5],2) + "  "
                                  + IntToHex(RDDataByLID[6],2) + "  "
                                  + IntToHex(RDDataByLID[7],2) + "  "
                                 );
           }
           break;
       case 6: //Input Status(Other)
           RDDataByLID[2]=0x60;
           RDDataByLID[3]=0x07;
           if(canWrite(Handle1,0x740,RDDataByLID,8,0)==canOK)
           {
             MemoText->Lines->Add("                      ");
             MemoText->Lines->Add("Read Other Input Status");
             MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(RDDataByLID[0],2) + "  "
                                  + IntToHex(RDDataByLID[1],2) + "  "
                                  + IntToHex(RDDataByLID[2],2) + "  "
                                  + IntToHex(RDDataByLID[3],2) + "  "
                                  + IntToHex(RDDataByLID[4],2) + "  "
                                  + IntToHex(RDDataByLID[5],2) + "  "
                                  + IntToHex(RDDataByLID[6],2) + "  "
                                  + IntToHex(RDDataByLID[7],2) + "  "
                                 );
           }
           break;
       case 7: //No Definition
           break;
       case 8: //Active Time Of Defrost
           RDDataByLID[2]=0x60;
           RDDataByLID[3]=0x08;
           if(canWrite(Handle1,0x740,RDDataByLID,8,0)==canOK)
           {
             MemoText->Lines->Add("                      ");
             MemoText->Lines->Add("Read Active Time Of Defrost");
             MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(RDDataByLID[0],2) + "  "
                                  + IntToHex(RDDataByLID[1],2) + "  "
                                  + IntToHex(RDDataByLID[2],2) + "  "
                                  + IntToHex(RDDataByLID[3],2) + "  "
                                  + IntToHex(RDDataByLID[4],2) + "  "
                                  + IntToHex(RDDataByLID[5],2) + "  "
                                  + IntToHex(RDDataByLID[6],2) + "  "
                                  + IntToHex(RDDataByLID[7],2) + "  "
                                 );
           }
           break;
       case 9: //Time For Stopping Battery Saver Output
           RDDataByLID[2]=0x60;
           RDDataByLID[3]=0x09;
           if(canWrite(Handle1,0x740,RDDataByLID,8,0)==canOK)
           {
             MemoText->Lines->Add("                      ");
             MemoText->Lines->Add("Read Time For Stopping Battery Saver");
             MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(RDDataByLID[0],2) + "  "
                                  + IntToHex(RDDataByLID[1],2) + "  "
                                  + IntToHex(RDDataByLID[2],2) + "  "
                                  + IntToHex(RDDataByLID[3],2) + "  "
                                  + IntToHex(RDDataByLID[4],2) + "  "
                                  + IntToHex(RDDataByLID[5],2) + "  "
                                  + IntToHex(RDDataByLID[6],2) + "  "
                                  + IntToHex(RDDataByLID[7],2) + "  "
                                 );
           }
           break;
       case 10: //The Speed Configuration Of Trunk Release Switch Forbidden
           RDDataByLID[2]=0x60;
           RDDataByLID[3]=0x0A;
           if(canWrite(Handle1,0x740,RDDataByLID,8,0)==canOK)
           {
             MemoText->Lines->Add("                      ");
             MemoText->Lines->Add("Read Trunk Speed Forbidden Configuration");
             MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(RDDataByLID[0],2) + "  "
                                  + IntToHex(RDDataByLID[1],2) + "  "
                                  + IntToHex(RDDataByLID[2],2) + "  "
                                  + IntToHex(RDDataByLID[3],2) + "  "
                                  + IntToHex(RDDataByLID[4],2) + "  "
                                  + IntToHex(RDDataByLID[5],2) + "  "
                                  + IntToHex(RDDataByLID[6],2) + "  "
                                  + IntToHex(RDDataByLID[7],2) + "  "
                                 );
           }
           break;
       case 11: //Active Time Of Horn
           RDDataByLID[2]=0x60;
           RDDataByLID[3]=0x0B;
           if(canWrite(Handle1,0x740,RDDataByLID,8,0)==canOK)
           {
             MemoText->Lines->Add("                      ");
             MemoText->Lines->Add("Read Active Time Of Horn");
             MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(RDDataByLID[0],2) + "  "
                                  + IntToHex(RDDataByLID[1],2) + "  "
                                  + IntToHex(RDDataByLID[2],2) + "  "
                                  + IntToHex(RDDataByLID[3],2) + "  "
                                  + IntToHex(RDDataByLID[4],2) + "  "
                                  + IntToHex(RDDataByLID[5],2) + "  "
                                  + IntToHex(RDDataByLID[6],2) + "  "
                                  + IntToHex(RDDataByLID[7],2) + "  "
                                 );
           }
           break;
       case 12: //CAN Configuration
           RDDataByLID[2]=0xD0;
           RDDataByLID[3]=0x09;
           if(canWrite(Handle1,0x740,RDDataByLID,8,0)==canOK)
           {
             MemoText->Lines->Add("                      ");
             MemoText->Lines->Add("Read CAN Configuration");
             MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(RDDataByLID[0],2) + "  "
                                  + IntToHex(RDDataByLID[1],2) + "  "
                                  + IntToHex(RDDataByLID[2],2) + "  "
                                  + IntToHex(RDDataByLID[3],2) + "  "
                                  + IntToHex(RDDataByLID[4],2) + "  "
                                  + IntToHex(RDDataByLID[5],2) + "  "
                                  + IntToHex(RDDataByLID[6],2) + "  "
                                  + IntToHex(RDDataByLID[7],2) + "  "
                                 );
           }
           break;
       case 13:  //ECU Serial Number
           RDDataByLID[2]=0xF1;
           RDDataByLID[3]=0x8C;
           if(canWrite(Handle1,0x740,RDDataByLID,8,0)==canOK)
           {
             MemoText->Lines->Add("                      ");
             MemoText->Lines->Add("Read ECU Serial Number");
             MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(RDDataByLID[0],2) + "  "
                                  + IntToHex(RDDataByLID[1],2) + "  "
                                  + IntToHex(RDDataByLID[2],2) + "  "
                                  + IntToHex(RDDataByLID[3],2) + "  "
                                  + IntToHex(RDDataByLID[4],2) + "  "
                                  + IntToHex(RDDataByLID[5],2) + "  "
                                  + IntToHex(RDDataByLID[6],2) + "  "
                                  + IntToHex(RDDataByLID[7],2) + "  "
                                 );
           }
           break;
       default:
           break;
    }
} 
//---------------------------------------------------------------------------

void __fastcall TMainForm::BusStateTimerTimer(TObject *Sender)
{
 {
   if((CBRead->ItemIndex<0)||(CBDiagMode->ItemIndex<0))
      ReadExcute->Enabled=false;
   else
      ReadExcute->Enabled=true;
 }

 {
   if((CBWrite->ItemIndex<0)||(CBDiagMode->ItemIndex<0))
      WriteExcute->Enabled=false;
   else
      WriteExcute->Enabled=true;
 }

 {
   if((CBRoutine->ItemIndex<0)||(CBDiagMode->ItemIndex<0))
      {
        Button8->Enabled=false;
        Button15->Enabled=false;
        Button14->Enabled=false;
      }
   else
      {
        Button8->Enabled=true;
        Button15->Enabled=true;
        Button14->Enabled=true;
      }
 }

 {
   if(CBDiagMode->ItemIndex<0)
      {
        Button9->Enabled=false;
        Button10->Enabled=false;
        CommCtrl->Enabled=false;
        BCMReset->Enabled=false;
        //Button1->Enabled=false;
      }
   else
      {
        Button9->Enabled=true;
        Button10->Enabled=true;
        CommCtrl->Enabled=true;
        BCMReset->Enabled=true;
        //Button1->Enabled=true;
      }
 }
}
//---------------------------------------------------------------------------





void __fastcall TMainForm::CBDiagModeChange(TObject *Sender)
{
   if(CBDiagMode->ItemIndex<0)
      CANRxTimer->Enabled=false;
   else
      CANRxTimer->Enabled=true;
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::CANRxTimerTimer(TObject *Sender)
{
  if(CBDiagMode->ItemIndex>0)
      canWrite(Handle1,0x740,TesterPresent,8,0);
  else
      {
        //do nothing
      }


   /* bool ScanData=true;
    //int stat;
    //long id;
    //unsigned int dlc, flags;
    unsigned char ReData[8];
    //-------------------------
    while(ScanData)
    {
        stat=canRead(Handle1,&id,ReData,&dlc,&flags,&timestamp);
        if((stat==canOK)&&(dlc>0)&&((int)id==DIAG_Req_ID))
           //CANRxTimer->Enabled=true;
        {
          ReceiveSts=true;
          for(unsigned int x=0;x<=dlc;x++)
            {
              switch(ReData[2])
              {
              case 0x10:
                DiagnosticSession[x]=ReData[x];
                break;

              case 0x11:
                Reset[x]=ReData[x];
                break;

              case 0x14:
                ClearDTC[x]=ReData[x];
                break;

              case 0x19:
                ReadDTC[x]=ReData[x];
                break;

              case 0x22:
                RDDataByLID[x]=ReData[x];
                break;

              case 0x27:
                {
                  if(ReData[3]==0x03)
                    SecurityAccess1[x]=ReData[x];
                  else
                    SecurityAccess2[x]=ReData[x];
                }
                break;

              case 0x28:
                CommunicationCtrl[x]=ReData[x];
                break;

              case 0x2E:
                WRDataByLID[x]=ReData[x];
                break;

              case 0x2F:
                IOControl[x]=ReData[x];
                break;

              case 0x31:
                RoutineControl[x]=ReData[x];
                break;

              case 0x3E:
                TesterPresent[x]=ReData[x];
                break;

              defalut:
                break;
              }
            }
          }

        else
        {
            ScanData=false;
        }
    }   */
}
//---------------------------------------------------------------------------




void __fastcall TMainForm::Button9Click(TObject *Sender)
{
    if(RadioButton3->Checked==true)
       {
       ReadDTC[0]=0x03;
       ReadDTC[2]=0x02;
       ReadDTC[3]=0x09;
       if(canWrite(Handle1,0x740,ReadDTC,8,0)==canOK)
           {
             MemoText->Lines->Add("                      ");
             MemoText->Lines->Add("Read Current DTC ");
             MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(ReadDTC[0],2) + "  "
                                  + IntToHex(ReadDTC[1],2) + "  "
                                  + IntToHex(ReadDTC[2],2) + "  "
                                  + IntToHex(ReadDTC[3],2) + "  "
                                  + IntToHex(ReadDTC[4],2) + "  "
                                  + IntToHex(ReadDTC[5],2) + "  "
                                  + IntToHex(ReadDTC[6],2) + "  "
                                  + IntToHex(ReadDTC[7],2) + "  "
                                 );
           }
       }

    else if(RadioButton10->Checked==true)
      {
      ReadDTC[0]=0x03;
      ReadDTC[2]=0x02;
      ReadDTC[3]=0x08;
      if(canWrite(Handle1,0x740,ReadDTC,8,0)==canOK)
           {
             MemoText->Lines->Add("                      ");
             MemoText->Lines->Add("Read History DTC ");
             MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(ReadDTC[0],2) + "  "
                                  + IntToHex(ReadDTC[1],2) + "  "
                                  + IntToHex(ReadDTC[2],2) + "  "
                                  + IntToHex(ReadDTC[3],2) + "  "
                                  + IntToHex(ReadDTC[4],2) + "  "
                                  + IntToHex(ReadDTC[5],2) + "  "
                                  + IntToHex(ReadDTC[6],2) + "  "
                                  + IntToHex(ReadDTC[7],2) + "  "
                                 );
           }
       }

      else if(RadioButton4->Checked==true)
      {
      ReadDTC[0]=0x02;
      ReadDTC[2]=0x0A;
      ReadDTC[3]=0x00;
      if(canWrite(Handle1,0x740,ReadDTC,8,0)==canOK)
           {
             MemoText->Lines->Add("                      ");
             MemoText->Lines->Add("Read All Supported DTC ");
             MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(ReadDTC[0],2) + "  "
                                  + IntToHex(ReadDTC[1],2) + "  "
                                  + IntToHex(ReadDTC[2],2) + "  "
                                  + IntToHex(ReadDTC[3],2) + "  "
                                  + IntToHex(ReadDTC[4],2) + "  "
                                  + IntToHex(ReadDTC[5],2) + "  "
                                  + IntToHex(ReadDTC[6],2) + "  "
                                  + IntToHex(ReadDTC[7],2) + "  "
                                 );
           }
       }

       else
       {
              /* do nothing */

       }
}
//---------------------------------------------------------------------------





void __fastcall TMainForm::Button10Click(TObject *Sender)
{
    if(canWrite(Handle1,0x740,ClearDTC,8,0)==canOK)
           {
             MemoText->Lines->Add("                      ");
             MemoText->Lines->Add("Clear DTC ");
             MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(ClearDTC[0],2) + "  "
                                  + IntToHex(ClearDTC[1],2) + "  "
                                  + IntToHex(ClearDTC[2],2) + "  "
                                  + IntToHex(ClearDTC[3],2) + "  "
                                  + IntToHex(ClearDTC[4],2) + "  "
                                  + IntToHex(ClearDTC[5],2) + "  "
                                  + IntToHex(ClearDTC[6],2) + "  "
                                  + IntToHex(ClearDTC[7],2) + "  "
                                 );
           }
    else
           {
             /*do nothing*/
           }
}
//---------------------------------------------------------------------------



void __fastcall TMainForm::Timer_TestpresentTimer(TObject *Sender)
{
     unsigned char data[8]={0x02,0x3E,0x00,0x00,0x00,0x00,0x00,0x00};

     if(canWrite(Handle1,0x740,data,8,0)==canOK)
     {
   /*         MemoText->Lines->Add(IntToHex(0x740,3)
                                  + "        "
                                  + IntToHex(RDDataByLID[0],2) + "  "
                                  + IntToHex(RDDataByLID[1],2) + "  "
                                  + IntToHex(RDDataByLID[2],2) + "  "
                                  + IntToHex(RDDataByLID[3],2) + "  "
                                  + IntToHex(RDDataByLID[4],2) + "  "
                                  + IntToHex(RDDataByLID[5],2) + "  "
                                  + IntToHex(RDDataByLID[6],2) + "  "
                                  + IntToHex(RDDataByLID[7],2) + "  "
                                 );   */
     }
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::BCMResetClick(TObject *Sender)
{
  if(RadioButton8->Checked==true)
  {
  Reset[2]=0x01;
    if(canWrite(Handle1,0x740,Reset,8,0)==canOK)
    {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Hardware Reset");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(Reset[0],2) + "  "
                           + IntToHex(Reset[1],2) + "  "
                           + IntToHex(Reset[2],2) + "  "
                           + IntToHex(Reset[3],2) + "  "
                           + IntToHex(Reset[4],2) + "  "
                           + IntToHex(Reset[5],2) + "  "
                           + IntToHex(Reset[6],2) + "  "
                           + IntToHex(Reset[7],2) + "  "
                                   );
    }
  }

  else if(RadioButton7->Checked==true)
  {
  Reset[2]=0x02;
    if(canWrite(Handle1,0x740,Reset,8,0)==canOK)
    {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Key Off ON Reset");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(Reset[0],2) + "  "
                           + IntToHex(Reset[1],2) + "  "
                           + IntToHex(Reset[2],2) + "  "
                           + IntToHex(Reset[3],2) + "  "
                           + IntToHex(Reset[4],2) + "  "
                           + IntToHex(Reset[5],2) + "  "
                           + IntToHex(Reset[6],2) + "  "
                           + IntToHex(Reset[7],2) + "  "
                                   );
    }
  }

  else if(RadioButton9->Checked==true)
  {
  Reset[2]=0x03;
    if(canWrite(Handle1,0x740,Reset,8,0)==canOK)
    {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Software Reset");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(Reset[0],2) + "  "
                           + IntToHex(Reset[1],2) + "  "
                           + IntToHex(Reset[2],2) + "  "
                           + IntToHex(Reset[3],2) + "  "
                           + IntToHex(Reset[4],2) + "  "
                           + IntToHex(Reset[5],2) + "  "
                           + IntToHex(Reset[6],2) + "  "
                           + IntToHex(Reset[7],2) + "  "
                                   );
    }
  }

  else
  return;

}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Button3Click(TObject *Sender)
{
  if(RadioButton13->Checked==true)
  {
  IOControl[0]=0x05;
  IOControl[4]=0x03;
  {
  if (CheckBox1->Checked==true)
    {
    IOControl[3]=0x00;
    IOControl[5]=0x01;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Left Turn IO Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox5->Checked==true)
    {
    IOControl[3]=0x00;
    IOControl[5]=0x02;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Left Turn IO Inactive Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox2->Checked==true)
    {
    IOControl[3]=0x01;
    IOControl[5]=0x01;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Right Turn IO Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }
  else if(CheckBox9->Checked==true)
    {
    IOControl[3]=0x01;
    IOControl[5]=0x02;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Right Turn IO Inactive Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox7->Checked==true)
    {
    IOControl[3]=0x05;
    IOControl[5]=0x01;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Front Fog Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox10->Checked==true)
    {
    IOControl[3]=0x05;
    IOControl[5]=0x02;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Front Fog Inactive Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox8->Checked==true)
    {
    IOControl[3]=0x06;
    IOControl[5]=0x01;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Rear Fog Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox11->Checked==true)
    {
    IOControl[3]=0x06;
    IOControl[5]=0x02;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Rear Fog Inactive Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox3->Checked==true)
    {
    IOControl[3]=0x07;
    IOControl[5]=0x01;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Daytime Running Light Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox12->Checked==true)
    {
    IOControl[3]=0x07;
    IOControl[5]=0x02;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Daytime Running Light Inactive Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox20->Checked==true)
    {
    IOControl[3]=0x20;
    IOControl[5]=0x01;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Front Left Window Up Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox25->Checked==true)
    {
    IOControl[3]=0x20;
    IOControl[5]=0x02;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Front Left Window Down Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox23->Checked==true)
    {
    IOControl[3]=0x21;
    IOControl[5]=0x01;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Front Right Window Up Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox24->Checked==true)
    {
    IOControl[3]=0x21;
    IOControl[5]=0x02;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Front Right Window Down Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox21->Checked==true)
    {
    IOControl[3]=0x22;
    IOControl[5]=0x01;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Rear Left Window Up Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox26->Checked==true)
    {
    IOControl[3]=0x22;
    IOControl[5]=0x02;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Rear Left Window Down Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox22->Checked==true)
    {
    IOControl[3]=0x23;
    IOControl[5]=0x01;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Rear Right Window Up Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox27->Checked==true)
    {
    IOControl[3]=0x23;
    IOControl[5]=0x02;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Rear Right Window Down Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox6->Checked==true)
    {
    IOControl[3]=0x24;
    IOControl[5]=0x01;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Central Lock Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox17->Checked==true)
    {
    IOControl[3]=0x24;
    IOControl[5]=0x02;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Central Unlock Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox18->Checked==true)
    {
    IOControl[3]=0x25;
    IOControl[5]=0x01;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Trunk Lock Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox19->Checked==true)
    {
    IOControl[3]=0x25;
    IOControl[5]=0x02;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Trunk Unlock Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox4->Checked==true)
    {
    IOControl[3]=0x30;
    IOControl[5]=0x01;
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Siren Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else
    {
       MemoText->Lines->Add("                      ");
       MemoText->Lines->Add("Please Select One of the Function!");
    }
  }
  }


  else if(RadioButton12->Checked==true)
  {
  IOControl[0]=0x04;
  IOControl[4]=0x00;
  {
  if (CheckBox1->Checked==true)
    {
    IOControl[3]=0x00;
    IOControl[5]=0x00;  //01 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Left Turn IO Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox5->Checked==true)
    {
    IOControl[3]=0x00;
    IOControl[5]=0x00;   //02 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Left Turn IO (Inactive) Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox2->Checked==true)
    {
    IOControl[3]=0x01;
    IOControl[5]=0x00;  //01 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Right Turn IO Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox9->Checked==true)
    {
    IOControl[3]=0x01;
    IOControl[5]=0x00;   //02 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Right Turn IO (Inactive) Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox7->Checked==true)
    {
    IOControl[3]=0x05;
    IOControl[5]=0x00;   //01 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Front Fog Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox10->Checked==true)
    {
    IOControl[3]=0x05;
    IOControl[5]=0x00;  //02 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Front Fog (Inactive) Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox2->Checked==true)
    {
    IOControl[3]=0x06;
    IOControl[5]=0x00;   //01 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Rear Fog Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox11->Checked==true)
    {
    IOControl[3]=0x06;
    IOControl[5]=0x00;  //02 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Rear Fog (Inactive) Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox3->Checked==true)
    {
    IOControl[3]=0x07;
    IOControl[5]=0x00;   //01 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Daytime Running Light Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox12->Checked==true)
    {
    IOControl[3]=0x07;
    IOControl[5]=0x00;   //02 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Daytime Running Light (Inactive) Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox20->Checked==true)
    {
    IOControl[3]=0x20;
    IOControl[5]=0x00;    //01 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Front Left Window Up Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox25->Checked==true)
    {
    IOControl[3]=0x20;
    IOControl[5]=0x00;    //02 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Front Left Window Down Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox23->Checked==true)
    {
    IOControl[3]=0x21;
    IOControl[5]=0x00;   //01 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Front Right Window Up Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox24->Checked==true)
    {
    IOControl[3]=0x21;
    IOControl[5]=0x00;    //02 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Front Right Window Down Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox21->Checked==true)
    {
    IOControl[3]=0x22;
    IOControl[5]=0x00;  //01 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Rear Left Window Up Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox26->Checked==true)
    {
    IOControl[3]=0x22;
    IOControl[5]=0x00;   //02 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Rear Left Window Down Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox22->Checked==true)
    {
    IOControl[3]=0x23;
    IOControl[5]=0x00;   //01 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Rear Right Window Up Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox27->Checked==true)
    {
    IOControl[3]=0x23;
    IOControl[5]=0x00;  //02 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Rear Right Window Down Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox6->Checked==true)
    {
    IOControl[3]=0x24;
    IOControl[5]=0x00;  //01 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Central Lock Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox17->Checked==true)
    {
    IOControl[3]=0x24;
    IOControl[5]=0x00;   //02 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Central Unlock Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox18->Checked==true)
    {
    IOControl[3]=0x25;
    IOControl[5]=0x00;   //01 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Trunk Lock Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox19->Checked==true)
    {
    IOControl[3]=0x25;
    IOControl[5]=0x00;    //02 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Trunk Unlock Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else if(CheckBox4->Checked==true)
    {
    IOControl[3]=0x30;
    IOControl[5]=0x00;   //01 changed to 00
      if(canWrite(Handle1,0x740,IOControl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Siren Return to ECU Control");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(IOControl[0],2) + "  "
                           + IntToHex(IOControl[1],2) + "  "
                           + IntToHex(IOControl[2],2) + "  "
                           + IntToHex(IOControl[3],2) + "  "
                           + IntToHex(IOControl[4],2) + "  "
                           + IntToHex(IOControl[5],2) + "  "
                           + IntToHex(IOControl[6],2) + "  "
                           + IntToHex(IOControl[7],2) + "  "
                                   );
      }
    }

  else
    {
       MemoText->Lines->Add("                      ");
       MemoText->Lines->Add("Please Select One of the Function!");
    }
  }
  }

}
//---------------------------------------------------------------------------

void __fastcall TMainForm::Button8Click(TObject *Sender)
{
  switch(CBRoutine->ItemIndex)
  {
    case 0:
    RoutineControl[2]=0x01;
    RoutineControl[3]=0x61;
    RoutineControl[4]=0x40;
    if(canWrite(Handle1,0x740,RoutineControl,8,0)==canOK)
    {
      MemoText->Lines->Add("                      ");
      MemoText->Lines->Add("Start Key Teach Routine");
      MemoText->Lines->Add(IntToHex(0x740,3)
                         + "        "
                         + IntToHex(RoutineControl[0],2) + "  "
                         + IntToHex(RoutineControl[1],2) + "  "
                         + IntToHex(RoutineControl[2],2) + "  "
                         + IntToHex(RoutineControl[3],2) + "  "
                         + IntToHex(RoutineControl[4],2) + "  "
                         + IntToHex(RoutineControl[5],2) + "  "
                         + IntToHex(RoutineControl[6],2) + "  "
                         + IntToHex(RoutineControl[7],2) + "  "
                                   );
    }
    break;

    case 1:
    RoutineControl[2]=0x01;
    RoutineControl[3]=0x61;
    RoutineControl[4]=0x41;
    if(canWrite(Handle1,0x740,RoutineControl,8,0)==canOK)
    {
      MemoText->Lines->Add("                      ");
      MemoText->Lines->Add("Erase All RF Keys Routine");
      MemoText->Lines->Add(IntToHex(0x740,3)
                         + "        "
                         + IntToHex(RoutineControl[0],2) + "  "
                         + IntToHex(RoutineControl[1],2) + "  "
                         + IntToHex(RoutineControl[2],2) + "  "
                         + IntToHex(RoutineControl[3],2) + "  "
                         + IntToHex(RoutineControl[4],2) + "  "
                         + IntToHex(RoutineControl[5],2) + "  "
                         + IntToHex(RoutineControl[6],2) + "  "
                         + IntToHex(RoutineControl[7],2) + "  "
                                   );
    }
    break;

    case 2:
    RoutineControl[2]=0x01;
    RoutineControl[3]=0x61;
    RoutineControl[4]=0x42;
    if(canWrite(Handle1,0x740,RoutineControl,8,0)==canOK)
    {
      MemoText->Lines->Add("                      ");
      MemoText->Lines->Add("Shipping Mode Routine");
      MemoText->Lines->Add(IntToHex(0x740,3)
                         + "        "
                         + IntToHex(RoutineControl[0],2) + "  "
                         + IntToHex(RoutineControl[1],2) + "  "
                         + IntToHex(RoutineControl[2],2) + "  "
                         + IntToHex(RoutineControl[3],2) + "  "
                         + IntToHex(RoutineControl[4],2) + "  "
                         + IntToHex(RoutineControl[5],2) + "  "
                         + IntToHex(RoutineControl[6],2) + "  "
                         + IntToHex(RoutineControl[7],2) + "  "
                                   );
    }
    break;

    default:
    break;
  }
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::Button15Click(TObject *Sender)
{
  switch(CBRoutine->ItemIndex)
  {
    case 0:
    RoutineControl[2]=0x03;
    RoutineControl[3]=0x61;
    RoutineControl[4]=0x40;
    if(canWrite(Handle1,0x740,RoutineControl,8,0)==canOK)
    {
      MemoText->Lines->Add("                      ");
      MemoText->Lines->Add("Key Teach Request");
      MemoText->Lines->Add(IntToHex(0x740,3)
                         + "        "
                         + IntToHex(RoutineControl[0],2) + "  "
                         + IntToHex(RoutineControl[1],2) + "  "
                         + IntToHex(RoutineControl[2],2) + "  "
                         + IntToHex(RoutineControl[3],2) + "  "
                         + IntToHex(RoutineControl[4],2) + "  "
                         + IntToHex(RoutineControl[5],2) + "  "
                         + IntToHex(RoutineControl[6],2) + "  "
                         + IntToHex(RoutineControl[7],2) + "  "
                                   );
    }
    break;

    case 1:
    RoutineControl[2]=0x03;
    RoutineControl[3]=0x61;
    RoutineControl[4]=0x41;
    if(canWrite(Handle1,0x740,RoutineControl,8,0)==canOK)
    {
      MemoText->Lines->Add("                      ");
      MemoText->Lines->Add("Erase All RF Keys Request");
      MemoText->Lines->Add(IntToHex(0x740,3)
                         + "        "
                         + IntToHex(RoutineControl[0],2) + "  "
                         + IntToHex(RoutineControl[1],2) + "  "
                         + IntToHex(RoutineControl[2],2) + "  "
                         + IntToHex(RoutineControl[3],2) + "  "
                         + IntToHex(RoutineControl[4],2) + "  "
                         + IntToHex(RoutineControl[5],2) + "  "
                         + IntToHex(RoutineControl[6],2) + "  "
                         + IntToHex(RoutineControl[7],2) + "  "
                                   );
    }
    break;

    case 2:
    RoutineControl[2]=0x03;
    RoutineControl[3]=0x61;
    RoutineControl[4]=0x42;
    if(canWrite(Handle1,0x740,RoutineControl,8,0)==canOK)
    {
      MemoText->Lines->Add("                      ");
      MemoText->Lines->Add("Shipping Mode Request");
      MemoText->Lines->Add(IntToHex(0x740,3)
                         + "        "
                         + IntToHex(RoutineControl[0],2) + "  "
                         + IntToHex(RoutineControl[1],2) + "  "
                         + IntToHex(RoutineControl[2],2) + "  "
                         + IntToHex(RoutineControl[3],2) + "  "
                         + IntToHex(RoutineControl[4],2) + "  "
                         + IntToHex(RoutineControl[5],2) + "  "
                         + IntToHex(RoutineControl[6],2) + "  "
                         + IntToHex(RoutineControl[7],2) + "  "
                                   );
    }
    break;

    default:
    break;
  }
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::Button14Click(TObject *Sender)
{
  switch(CBRoutine->ItemIndex)
  {
    case 0:
    RoutineControl[2]=0x02;
    RoutineControl[3]=0x61;
    RoutineControl[4]=0x40;
    if(canWrite(Handle1,0x740,RoutineControl,8,0)==canOK)
    {
      MemoText->Lines->Add("                      ");
      MemoText->Lines->Add("Stop Key Teach");
      MemoText->Lines->Add(IntToHex(0x740,3)
                         + "        "
                         + IntToHex(RoutineControl[0],2) + "  "
                         + IntToHex(RoutineControl[1],2) + "  "
                         + IntToHex(RoutineControl[2],2) + "  "
                         + IntToHex(RoutineControl[3],2) + "  "
                         + IntToHex(RoutineControl[4],2) + "  "
                         + IntToHex(RoutineControl[5],2) + "  "
                         + IntToHex(RoutineControl[6],2) + "  "
                         + IntToHex(RoutineControl[7],2) + "  "
                                   );
    }
    break;

    case 1:
    RoutineControl[2]=0x02;
    RoutineControl[3]=0x61;
    RoutineControl[4]=0x41;
    if(canWrite(Handle1,0x740,RoutineControl,8,0)==canOK)
    {
      MemoText->Lines->Add("                      ");
      MemoText->Lines->Add("Stop Erase All RF Keys");
      MemoText->Lines->Add(IntToHex(0x740,3)
                         + "        "
                         + IntToHex(RoutineControl[0],2) + "  "
                         + IntToHex(RoutineControl[1],2) + "  "
                         + IntToHex(RoutineControl[2],2) + "  "
                         + IntToHex(RoutineControl[3],2) + "  "
                         + IntToHex(RoutineControl[4],2) + "  "
                         + IntToHex(RoutineControl[5],2) + "  "
                         + IntToHex(RoutineControl[6],2) + "  "
                         + IntToHex(RoutineControl[7],2) + "  "
                                   );
    }
    break;

    case 2:
    RoutineControl[2]=0x02;
    RoutineControl[3]=0x61;
    RoutineControl[4]=0x42;
    if(canWrite(Handle1,0x740,RoutineControl,8,0)==canOK)
    {
      MemoText->Lines->Add("                      ");
      MemoText->Lines->Add("Stop Shipping Mode");
      MemoText->Lines->Add(IntToHex(0x740,3)
                         + "        "
                         + IntToHex(RoutineControl[0],2) + "  "
                         + IntToHex(RoutineControl[1],2) + "  "
                         + IntToHex(RoutineControl[2],2) + "  "
                         + IntToHex(RoutineControl[3],2) + "  "
                         + IntToHex(RoutineControl[4],2) + "  "
                         + IntToHex(RoutineControl[5],2) + "  "
                         + IntToHex(RoutineControl[6],2) + "  "
                         + IntToHex(RoutineControl[7],2) + "  "
                                   );
    }
    break;

    default:
    break;
  }
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::CommCtrlClick(TObject *Sender)
{
  if(CheckBox43->Checked==true && CheckBox44->Checked==false)
  {
    CommunicationCtrl[2]=0x00;
    if(RadioButton11->Checked==true)
    {
      CommunicationCtrl[3]=0x02;
      if(canWrite(Handle1,0x740,CommunicationCtrl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Network Management Communication Messages");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(CommunicationCtrl[0],2) + "  "
                           + IntToHex(CommunicationCtrl[1],2) + "  "
                           + IntToHex(CommunicationCtrl[2],2) + "  "
                           + IntToHex(CommunicationCtrl[3],2) + "  "
                           + IntToHex(CommunicationCtrl[4],2) + "  "
                           + IntToHex(CommunicationCtrl[5],2) + "  "
                           + IntToHex(CommunicationCtrl[6],2) + "  "
                           + IntToHex(CommunicationCtrl[7],2) + "  "
                                     );
      }
    }

    else if(RadioButton5->Checked==true)
    {
      CommunicationCtrl[3]=0x01;
      if(canWrite(Handle1,0x740,CommunicationCtrl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Normal communication Messages");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(CommunicationCtrl[0],2) + "  "
                           + IntToHex(CommunicationCtrl[1],2) + "  "
                           + IntToHex(CommunicationCtrl[2],2) + "  "
                           + IntToHex(CommunicationCtrl[3],2) + "  "
                           + IntToHex(CommunicationCtrl[4],2) + "  "
                           + IntToHex(CommunicationCtrl[5],2) + "  "
                           + IntToHex(CommunicationCtrl[6],2) + "  "
                           + IntToHex(CommunicationCtrl[7],2) + "  "
                                     );
      }
    }

    else if(RadioButton6->Checked==true)
    {
      CommunicationCtrl[3]=0x03;
      if(canWrite(Handle1,0x740,CommunicationCtrl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Network Management && Normal communication Messages");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(CommunicationCtrl[0],2) + "  "
                           + IntToHex(CommunicationCtrl[1],2) + "  "
                           + IntToHex(CommunicationCtrl[2],2) + "  "
                           + IntToHex(CommunicationCtrl[3],2) + "  "
                           + IntToHex(CommunicationCtrl[4],2) + "  "
                           + IntToHex(CommunicationCtrl[5],2) + "  "
                           + IntToHex(CommunicationCtrl[6],2) + "  "
                           + IntToHex(CommunicationCtrl[7],2) + "  "
                                     );
      }
    }
  }

  else if(CheckBox44->Checked==true && CheckBox43->Checked==false)
  {
    CommunicationCtrl[2]=0x03;
    if(RadioButton11->Checked==true)
    {
      CommunicationCtrl[3]=0x02;
      if(canWrite(Handle1,0x740,CommunicationCtrl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Network Management Communication Messages");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(CommunicationCtrl[0],2) + "  "
                           + IntToHex(CommunicationCtrl[1],2) + "  "
                           + IntToHex(CommunicationCtrl[2],2) + "  "
                           + IntToHex(CommunicationCtrl[3],2) + "  "
                           + IntToHex(CommunicationCtrl[4],2) + "  "
                           + IntToHex(CommunicationCtrl[5],2) + "  "
                           + IntToHex(CommunicationCtrl[6],2) + "  "
                           + IntToHex(CommunicationCtrl[7],2) + "  "
                                     );
      }
    }

    else if(RadioButton5->Checked==true)
    {
      CommunicationCtrl[3]=0x01;
      if(canWrite(Handle1,0x740,CommunicationCtrl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Normal communication Messages");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(CommunicationCtrl[0],2) + "  "
                           + IntToHex(CommunicationCtrl[1],2) + "  "
                           + IntToHex(CommunicationCtrl[2],2) + "  "
                           + IntToHex(CommunicationCtrl[3],2) + "  "
                           + IntToHex(CommunicationCtrl[4],2) + "  "
                           + IntToHex(CommunicationCtrl[5],2) + "  "
                           + IntToHex(CommunicationCtrl[6],2) + "  "
                           + IntToHex(CommunicationCtrl[7],2) + "  "
                                     );
      }
    }

    else if(RadioButton6->Checked==true)
    {
      CommunicationCtrl[3]=0x03;
      if(canWrite(Handle1,0x740,CommunicationCtrl,8,0)==canOK)
      {
        MemoText->Lines->Add("                      ");
        MemoText->Lines->Add("Network Management && Normal communication Messages");
        MemoText->Lines->Add(IntToHex(0x740,3)
                           + "        "
                           + IntToHex(CommunicationCtrl[0],2) + "  "
                           + IntToHex(CommunicationCtrl[1],2) + "  "
                           + IntToHex(CommunicationCtrl[2],2) + "  "
                           + IntToHex(CommunicationCtrl[3],2) + "  "
                           + IntToHex(CommunicationCtrl[4],2) + "  "
                           + IntToHex(CommunicationCtrl[5],2) + "  "
                           + IntToHex(CommunicationCtrl[6],2) + "  "
                           + IntToHex(CommunicationCtrl[7],2) + "  "
                                     );
      }
    }
  }

  else if(CheckBox44->Checked==false && CheckBox43->Checked==false)
  {
    MemoText->Lines->Add("                      ");
    MemoText->Lines->Add("Please select EnableRX TX or DisableRx TX");
  }
  else if(CheckBox44->Checked==true && CheckBox43->Checked==true)
  {
    MemoText->Lines->Add("                      ");
    MemoText->Lines->Add("Both EnableRx TX and DisableRX TX chose is forbidden");
  }
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::Button7Click(TObject *Sender)
{
  if(canWrite(Handle1,0x740,TesterPresent,8,0)==canOK)
  {
    {
      MemoText->Lines->Add("                      ");
      MemoText->Lines->Add("Tester Present");
      MemoText->Lines->Add(IntToHex(0x740,3)
                             + "        "
                             + IntToHex(TesterPresent[0],2) + "  "
                             + IntToHex(TesterPresent[1],2) + "  "
                             + IntToHex(TesterPresent[2],2) + "  "
                             + IntToHex(TesterPresent[3],2) + "  "
                             + IntToHex(TesterPresent[4],2) + "  "
                             + IntToHex(TesterPresent[5],2) + "  "
                             + IntToHex(TesterPresent[6],2) + "  "
                             + IntToHex(TesterPresent[7],2) + "  "
                                       );
    }
    {
      stat=canRead(Handle1, &id, RxData, &dlc, &flags, &timestamp);
      if ((stat == canOK ) &&  (dlc>0) && (RxData[1] == 0x7E))
      {
        MemoText->Lines->Add(IntToHex(0x750,3) +  "        "
                       + IntToHex(RxData[0],2) + "  "
                       + IntToHex(RxData[1],2) + "  "
                       + IntToHex(RxData[2],2) + "  "
                       + IntToHex(RxData[3],2) + "  "
                       + IntToHex(RxData[4],2) + "  "
                       + IntToHex(RxData[5],2) + "  "
                       + IntToHex(RxData[6],2) + "  "
                       + IntToHex(RxData[7],2) );
      }
    }
  }


  else
  {
    //do nothing
  }
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::WriteExcuteClick(TObject *Sender)
{
  switch(CBWrite->ItemIndex)
  {
    case 0:
    WRDataByLID[2]=0x60;
    WRDataByLID[3]=0x08;
    //AnsiString Tempx="";
    Tempx="0x"+Edit1->Text;
    WRDataByLID[4]=(unsigned char)Tempx.ToInt();
    if(canWrite(Handle1,0x740,WRDataByLID,8,0)==canOK)
    {
      MemoText->Lines->Add("                      ");
      MemoText->Lines->Add("Write Active Time Of Defrost");
      MemoText->Lines->Add(IntToHex(0x740,3)
                              + "        "
                              + IntToHex(WRDataByLID[0],2) + "  "
                              + IntToHex(WRDataByLID[1],2) + "  "
                              + IntToHex(WRDataByLID[2],2) + "  "
                              + IntToHex(WRDataByLID[3],2) + "  "
                              + IntToHex(WRDataByLID[4],2) + "  "
                              + IntToHex(WRDataByLID[5],2) + "  "
                              + IntToHex(WRDataByLID[6],2) + "  "
                              + IntToHex(WRDataByLID[7],2) + "  "
                                        );
    }
    break;

    case 1:
    WRDataByLID[2]=0x60;
    WRDataByLID[3]=0x09;
    //AnsiString Tempx="";
    Tempx="0x"+Edit2->Text;
    WRDataByLID[4]= (unsigned char)Tempx.ToInt();
    if(canWrite(Handle1,0x740,WRDataByLID,8,0)==canOK)
    {
      MemoText->Lines->Add("                      ");
      MemoText->Lines->Add("Write Time For Stopping Battery Saver Output");
      MemoText->Lines->Add(IntToHex(0x740,3)
                              + "        "
                              + IntToHex(WRDataByLID[0],2) + "  "
                              + IntToHex(WRDataByLID[1],2) + "  "
                              + IntToHex(WRDataByLID[2],2) + "  "
                              + IntToHex(WRDataByLID[3],2) + "  "
                              + IntToHex(WRDataByLID[4],2) + "  "
                              + IntToHex(WRDataByLID[5],2) + "  "
                              + IntToHex(WRDataByLID[6],2) + "  "
                              + IntToHex(WRDataByLID[7],2) + "  "
                                        );
    }
    break;

    case 2:
    WRDataByLID[2]=0x60;
    WRDataByLID[3]=0x0A;
    //AnsiString Tempx="";
    Tempx="0x"+Edit3->Text;
    WRDataByLID[4]= (unsigned char)Tempx.ToInt();
    if(canWrite(Handle1,0x740,WRDataByLID,8,0)==canOK)
    {
      MemoText->Lines->Add("                      ");
      MemoText->Lines->Add("Write The Speed Configuration Of Trunk Release Switch Forbidden");
      MemoText->Lines->Add(IntToHex(0x740,3)
                              + "        "
                              + IntToHex(WRDataByLID[0],2) + "  "
                              + IntToHex(WRDataByLID[1],2) + "  "
                              + IntToHex(WRDataByLID[2],2) + "  "
                              + IntToHex(WRDataByLID[3],2) + "  "
                              + IntToHex(WRDataByLID[4],2) + "  "
                              + IntToHex(WRDataByLID[5],2) + "  "
                              + IntToHex(WRDataByLID[6],2) + "  "
                              + IntToHex(WRDataByLID[7],2) + "  "
                                        );
    }
    break;

    case 3:
    WRDataByLID[2]=0x60;
    WRDataByLID[3]=0x0B;
   // AnsiString Tempx="";
    //Tempx="0x"+Edit3->Text;
    //WRDataByLID[4]= Tempx;
    {
      if(RadioButton1->Checked==true)
        WRDataByLID[4]=0x14;

      else if(RadioButton2->Checked==true)
        WRDataByLID[4]=0x3C;
    }
    if(canWrite(Handle1,0x740,WRDataByLID,8,0)==canOK)
    {
      MemoText->Lines->Add("                      ");
      MemoText->Lines->Add("Write Active Time Of Horn");
      MemoText->Lines->Add(IntToHex(0x740,3)
                              + "        "
                              + IntToHex(WRDataByLID[0],2) + "  "
                              + IntToHex(WRDataByLID[1],2) + "  "
                              + IntToHex(WRDataByLID[2],2) + "  "
                              + IntToHex(WRDataByLID[3],2) + "  "
                              + IntToHex(WRDataByLID[4],2) + "  "
                              + IntToHex(WRDataByLID[5],2) + "  "
                              + IntToHex(WRDataByLID[6],2) + "  "
                              + IntToHex(WRDataByLID[7],2) + "  "
                                        );
    }
    break;

    case 4:
    WRDataByLID[0]=0x10;
    WRDataByLID[1]=0x0B;
    WRDataByLID[2]=0x2E;
    WRDataByLID[3]=0xD0;
    WRDataByLID[4]=0x09;
    //AnsiString Tempx="";

    Tempx="0x"+Edit15->Text;
    WRDataByLID[5]= (unsigned char)Tempx.ToInt();

    Tempx="0x"+Edit14->Text;
    WRDataByLID[6]= (unsigned char)Tempx.ToInt();

    Tempx="0x"+Edit13->Text;
    WRDataByLID[7]= (unsigned char)Tempx.ToInt();
    if(canWrite(Handle1,0x740,WRDataByLID,8,0)==canOK)
    {
      MemoText->Lines->Add("                      ");
      MemoText->Lines->Add("Write CAN Configuration");
      MemoText->Lines->Add(IntToHex(0x740,3)
                              + "        "
                              + IntToHex(WRDataByLID[0],2) + "  "
                              + IntToHex(WRDataByLID[1],2) + "  "
                              + IntToHex(WRDataByLID[2],2) + "  "
                              + IntToHex(WRDataByLID[3],2) + "  "
                              + IntToHex(WRDataByLID[4],2) + "  "
                              + IntToHex(WRDataByLID[5],2) + "  "
                              + IntToHex(WRDataByLID[6],2) + "  "
                              + IntToHex(WRDataByLID[7],2) + "  "
                                        );
    }
    
    default:
    break;
  }
}
//---------------------------------------------------------------------------


